home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Format CD 46
/
Amiga Format CD46 (1999-10-20)(Future Publishing)(GB)[!][issue 1999-12].iso
/
-in_the_mag-
/
reader_requests
/
scilab
/
tests
/
auto.dia.ref
< prev
next >
Wrap
Text File
|
1999-09-16
|
6KB
|
407 lines
// test conversion transfer <---> state-space
// 1- coff inversion
s=poly(0,'s'); a=[1 2 3;4 5 6;7 8 9];
[num,den]=coff(a,'s');h1=num/den;h2=(s*eye-a)**(-1);
e=h1-h2;if norm(coeff(e(2)))>5000*%eps then bugmes();quit;end
// 2-test de tf2ss et ss2tf
n=[1+s 2+3*s+4*s**2 5; 0 1-s s];
d=[1+3*s 5-s**3 s+1;1+s 1+s+s**2 3*s-1];
h=syslin('c',n./d);
[n,d]=simp(n,d);if h<>tlist('r',n,d,'c') then bugmes();quit;end
sl=tf2ss(h); e=h-ss2tf(sl);
if norm(coeff(e(2)))>100000*%eps then bugmes();quit;end
//
a = [0.8604043 , 0.0070020 , 0.6223373 , -1.356213 , -4.2301775
0.159714 , 0.0857791 , -0.2367751 , 0.4958580 , 0.6398817
-4.3054931 , -0.0365878 , 2.1784911 , 0.0314793 , 2.3728994
-3.7115779 , -0.5370809 , 2.4291716 , -0.6352663 , 2.6972781
6.3580966 , 0.1377712 , -4.0461243 , -0.5192899 , -4.0394083];
b = [-0.0532544 , -0.1494083 , -0.0098619
-0.0355030 , -0.0162722 , 0.1045365
-0.1301775 , 0.1736686 , -0.0611440
0.1834320 , 0.1757396 , -0.5956607
0.1775148 , -0.1186391 , 0.1439842];
c = [2 , 7 , -2 , 5 , 1
0 , -1 , 3 , 0 , 2];
d = [1 , 0 , 0
0 , 0 , 0];
sl=syslin('c',a,b,c);
if sl<>tlist('lss',a,b,c,0*ones(2,3),0*ones(5,1),'c') then bugmes();quit;end
//
eps=sqrt(%eps);
if contr(a,b,eps)<>4 then bugmes();quit;end
if contr(a',c',eps)<>3 then bugmes();quit;end
spec(a);
xbasc();xselect();
plzr(sl)
//
slc=contrss(sl,eps);ssprint(slc)
|-1.0289055 -1.91259 6.6863837 -2.3911949 |
. |-0.0955268 -1.5790365 7.5050866 -1.8143246 |
x = | 0.0758051 -4.2025605 2.3519864 -1.6769419 |x
| 0.3692750 -2.0727197 1.1533554 -1.2940444 |
|-0.1263403 -0.212262 0.6247454 |
| 0.2650276 -0.1121187 0 |
+ | 0 -0.2002056 0 |u
| 0 0 0 |
|-3.2013033 2.2471114 2.1356648 -2.2749904 |
y = |-1.602D-07 3.012D-07 -1.4984584 3.4285015 |x
slo=obsvss(sl,eps);ssprint(slo)
. |-0.4272289 -0.2662516 0.2081474 |
x = | 0.3415366 -0.5532610 -0.3279827 |x
| 0.9676787 0.1381688 -0.5695102 |
|-0.1097643 3.290D-08 0.2195285 |
+ | 0.0374221 0.0847100 -0.0748442 |u
| 0.2180784 0.0514041 -0.4361566 |
|-9.1104336 0 0 |
y = | 1.2074069 3.5414924 0 |x
slm=minss(sl,eps);ssprint(slm)
. |-1.0328573 -0.5017879 | | 0.2469955 0.0582203 -0.4939909 |
x = | 0.3895376 -0.5171428 |x + |-1.340D-08 -0.0801783 0 |u
| 4.0486569 2.9398764 |
y = | 2.025D-07 -3.7416574 |x
//
hm=ss2tf(slm);
h=ss2tf(sl);
hh=c*(s*eye-a)**(-1)*b + 0*ones(2,3);
hh=hh-h;
if norm(coeff(hh(2))) > 1.e-5 then bugmes();quit;end
[num,den]=coff(a,'s');
hh=c*real(num)*b/real(den) + 0*ones(2,3);
hh=hh-h;
if norm(coeff(hh(2))) > 1.e-5 then bugmes();quit;end
slh=tf2ss(hm) //was tf2ss(h)
slh =
slh(1) (state-space system:)
lss
slh(2) = A matrix =
! - 0.8120643 0.3708242 !
! - 0.3515107 - 0.7379359 !
slh(3) = B matrix =
! - 1.3958683 4.188D-07 2.7917359 !
! - 0.2336248 - 0.4065365 0.4672493 !
slh(4) = C matrix =
! - 0.7164 0. !
! 0.1235081 - 0.7379406 !
slh(5) = D matrix =
! 0. 0. 0. !
! 0. 0. 0. !
slh(6) = X0 (initial state) =
! 0. !
! 0. !
slh(7) = Time domain =
c
//
u=eye(3,60);
xbasc();
;
plot2d1("enn",1,flts(u,dscr(slh,0.3))');
plot2d1("enn",1,flts(u,dscr(sl,0.3))',[-3,-4],"101")
//csim flts
//definition
ti=2.7;k=0.87;td=0.69;n=200;
a=[0 0 0 0 0 -1/ti
0 -n/td 0 0 0 n/td
k n -1 0 0 -k-n
0 0 1 -1 0 0
0 0 0 1 -1 0
0 0 0 0 1 -1];
b=[1/ti;0;k;0;0;0];
c=[0 0 0 0 0 1];
tech=0.2;t=0:tech:15; //
deff('[y]=u(t)','if t=0 then y=0;else y=1,end') //step
// avec csim
if type(csim)<>13 then comp(csim);end
sl=syslin('c',a,b,c);
//comparison
// csim
xbasc(xget("window"));
plot2d(t',csim(u,t,sl)')
plot2d(t',csim('ech',t,sl)',-2,"001")
//exact discretization
sld=dscr(sl,tech);
plot2d(t',flts(ones(t),sld)',-3,"001")
//
//impulse responses
//
;xbasc();
plot2d(t',csim('imp',t,sl)')
//discretization
plot2d(t',flts(eye(t)/tech,sld)',-2,"001");
//fin
;xbasc();
//test bode - black et nyquist
s=poly(0,'s')
s =
s
// n=poly(1,'s','c'); d=real(poly([5+15*%i,5-15*%i],'s'))
n=1+s;d=1+2*s;
h=syslin('c',n,d)
h =
1 + s
-----
1 + 2s
sl=tf2ss(h);
sld=dscr(sl,0.01);
hd=ss2tf(sld);
[w,rf]=repfreq(h,0.01,100);
//
//transfer
bode(h,0.01,100);
;xbasc();
bode(h,0.01,100,0.01)
;xbasc();
bode(sl,0.01,100);
;xbasc();
bode(sl,0.01,100,0.01)
;xbasc();
//
bode(w,rf)
;xbasc();
bode(w,20*log(abs(rf))/log(10),(180/%pi)*atan(imag(rf),real(rf)))
;xbasc();
//
//transfer
bode(sld,0.001,1)
// bode(sld,0.001,1,0.01)
//
;xbasc();
// bode(hd,0.001,1)
bode(hd,0.001,1,0.01)
//
//
//nyquist
//
;xbasc();
nyquist(h,0.01,100); nyquist(h,0.01,100,0.01);
;xbasc();
nyquist(sl,0.01,100); nyquist(sl,0.01,100,0.01);
;xbasc();
nyquist(w,rf);
nyquist(w,20*log(abs(rf))/log(10),(180/%pi)*atan(imag(rf),real(rf)));
//
//nyquist(sld,0.001,1);nyquist(sld,0.001,1,0.01);
;xbasc();
//nyquist(hd,0.001,1);nyquist(hd,0.001,1,0.01);
;xbasc();
//
//black
//
black(h,0.01,100); black(h,0.01,100,0.01);
;xbasc();
black(sl,0.01,100); black(sl,0.01,100,0.01);
;xbasc();
black(w,rf);
;xbasc();
black(w,20*log(abs(rf))/log(10),(180/%pi)*atan(imag(rf),real(rf)));
//
;xbasc();
black(sld,0.001,1);black(sld,0.001,1,0.01);
;xbasc();
black(hd,0.001,1);black(hd,0.001,1,0.01);
;xbasc();
//
//test dscr
slc=syslin('c',[0 1;0 0],[0;0],[1,0]);qc=[0 0;0 0.1]
qc =
! 0. 0. !
! 0. 0.1 !
qd=ones(2,2)./[30000 2000;2000 100];
sld=syslin(0.1,[1 0.1;0 1],[0;0],[1 0]);
[s1]=dscr(slc,0.1);
if norm(s1(2)-sld(2))>10*%eps then bugmes();quit;end
if norm(s1(3)-sld(3))>10*%eps then bugmes();quit;end
[s1,r]=dscr(slc,0.1,qc);
if norm(s1(2)-sld(2))>10*%eps then bugmes();quit;end
if norm(s1(3)-sld(3))>10*%eps then bugmes();quit;end
if norm(r-qd)>10*%eps then bugmes();quit;end